﻿@model TbShop.Web.Areas.Admin.Models.AdministratorDetailViewModel

@{
    var isNew = Model.Id == "";
    var opt = isNew ? "新增" : "修改";
    ViewBag.ModuleId = "Administrator";
    ViewBag.Title = opt + "管理员";
}
<style>
    .float-left {
        float: left;
        width: 50%;
        padding-right: 50px;
    }
</style>
<div class="box box-primary">
    @using (Html.BeginForm("Edit", "Administrator", FormMethod.Post, new { @enctype = "multipart/form-data", @validate = "" }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.OldRoleId)
        @Html.HiddenFor(model => model.CreatedDate)
        <div class="box-body">
            <div class="form-group">
                <label for="Shortcut">头像</label>
                @if (!string.IsNullOrWhiteSpace(Model.HeadPortrait))
                {
                    <br />
                    <img src="@Model.HeadPortrait" onerror="imageError($(this));" width="100" height="100" />
                    <br />
                    <br />
                }
                <input type="file" name="shortcutImg" accept="image/x-png,image/jpeg,image/x-ms-bmp" />
                @Html.HiddenFor(model => model.HeadPortrait)
            </div>
            <div class="form-group">
                <label for="UserName">@(Html.Raw(isNew ? "<strong class=\"notes\">*</strong>" : ""))登录账号</label>
                @if (isNew)
                {
                    @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", @validate = "", placeholder = "登录帐号" })
                }
                else
                {
                    @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", @disabled = "disabled" })
                    @Html.HiddenFor(model => model.UserName)
                }
            </div>
            <div class="form-group">
                <label for="Name"><strong class="notes">*</strong>账号名称</label>
                @Html.TextBoxFor(model => model.Name, new { @class = "form-control", @validate = "", placeholder = "姓名" })
            </div>
            @if (string.IsNullOrWhiteSpace(Model.Id))
            {
                <div class="form-group">
                    <label for="Password"><strong class="notes">*</strong>密码</label>
                    @Html.PasswordFor(model => model.Password, new { @class = "form-control", @validate = "", placeholder = "密码" })
                </div>
            }
            else
            {
                @Html.HiddenFor(model => model.Password)
            }
            <div class="form-group">
                <label for="RoleId"><strong class="notes">*</strong>所属角色</label>
                @Html.DropDownListFor(model => model.RoleId, Model.RolesList, new { @class = "form-control",  @validate = "" })
            </div>

            <div class="form-group">
                <label for="PhoneNumber"><strong class="notes">*</strong>联系方式</label>
                @Html.TextBoxFor(model => model.PhoneNumber, new { @class = "form-control", @validate = "", placeholder = "电话" })
            </div>
            <div class="form-group">
                <label for="Address"><strong class="notes">*</strong>联系地址</label>
                @Html.TextBoxFor(model => model.Address, new { @class = "form-control", @validate = "", placeholder = "联系地址" })
            </div>
            <div class="box-footer">
                <button type="submit" class="btn btn-primary">保存</button>
                <a href="@(Url.Action("Index", "Administrator"))" class="btn btn-default">返回</a>
            </div>
        </div>
    }
</div>
<script>
    $(document).ready(function () {
        $("#RoleId").change(function () {
            changeRoleId($(this).val());
        });
        changeRoleId($("#RoleId").val());
    });
    function changeRoleId(roleId){
        if (roleId == "@Constants.SystemParameterKeys.SalesmanId") {
            $('.for-salesman').show();
        } else {
            $('.for-salesman').hide();
        }
    }
</script>